﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace YXShop.Web.membercenter.shop.shop_product
{
    public partial class product_auction_list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
               
                if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != "" && ChangeHope.WebPage.PageRequest.GetFormString("id") != "")
                {
                    string types = Request.Form["Option"].Trim();
                    string id = ChangeHope.WebPage.PageRequest.GetFormString("id");
                    if (types == "del")
                    {
                        del(id);
                    }
                    Response.End();
                    return;
                }
                this.Literal1.Text = GetList();
            }
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        protected string GetList()
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            YXShop.BLL.Product.ProductAuction data = new YXShop.BLL.Product.ProductAuction();
            ChangeHope.DataBase.DataByPage dataPage = data.GetList(" [order by] id asc", 20, " and putoutid=" + Session["MemberID"].ToString() + " and endtime < getDate() ");
            //第一步先添加表头
            table.AddHeadCol("8%", "序号<input type=\"checkbox\" id=\"chkAll\" onclick=\"CheckAll(this.form)\" alt=\"全选/取消\" />");
            table.AddHeadCol("10%", "拍卖名称");
            table.AddHeadCol("15%", "商品名称");
            table.AddHeadCol("12%", "开始时间");
            table.AddHeadCol("12%", "结束时间");
            table.AddHeadCol("8%", "保证金");
            table.AddHeadCol("8%", "起拍价");
            table.AddHeadCol("8%", "加价幅度");
            table.AddHeadCol("17%", "操作");
            table.AddRow();
            //添加表的内容
            if (dataPage.DataReader != null)
            {
                int curpage = ChangeHope.WebPage.PageRequest.GetInt("pageindex");
                if (curpage < 0)
                {
                    curpage = 1;
                }
                int count = 0;
                while (dataPage.DataReader.Read())
                {
                    count++;
                    string No = (15 * (curpage - 1) + count).ToString();
                    table.AddCol(No + "<input ID=\"cBox\" type=\"checkbox\" value=\"" + dataPage.DataReader["id"].ToString() + "\" />");
                    table.AddCol(dataPage.DataReader["auctionname"].ToString());
                    table.AddCol(dataPage.DataReader["productName"].ToString());
                    table.AddCol(dataPage.DataReader["starttime"].ToString());
                    table.AddCol(dataPage.DataReader["endtime"].ToString());
                    table.AddCol(dataPage.DataReader["deposit"].ToString());
                    table.AddCol(dataPage.DataReader["price"].ToString());
                    table.AddCol(dataPage.DataReader["pricerange"].ToString());
                    string url = YXShop.TemplateAction.Common.UrlStr("product_auction_edit", "id=" + dataPage.DataReader["id"].ToString(), "membercenter/shop/shop_product/");
                    string urlBid = YXShop.TemplateAction.Common.UrlStr("auction_bid_info", "w_d_productid=" + dataPage.DataReader["productid"].ToString(), "membercenter/shop/shop_product/");
                    table.AddCol(string.Format("<a href=\""+url+"\">编辑</a> <a href='#' onclick='Del({0})'>删除</a><br> {1} <a href=\""+urlBid+"\">出价记录</a>", dataPage.DataReader["id"].ToString(),ProductClassID(dataPage.DataReader["productid"].ToString())));
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }

        protected string ProductClassID(string ID)
        {
            string str = "<span style='color:#666666'>查看</span>";
            if (!string.IsNullOrEmpty(ID))
            {
                YXShop.BLL.Product.ProductInfo dll = new YXShop.BLL.Product.ProductInfo();
                YXShop.Model.Product.ProductInfo model = dll.GetModel(Convert.ToInt32(ID));
                if (model != null)
                {
                    string url = YXShop.TemplateAction.Common.UrlStr("product_edit", "cid=" + model.pro_ID + ";id=" + ID, "membercenter/shop/shop_product/");
                    str = "<a href=\""+url+"\">查看</a>";
                }
            }
            return str;
        }

        private void del(string id)
        {
            YXShop.BLL.Product.ProductAuction bll = new YXShop.BLL.Product.ProductAuction();
            bll.Delete(id);
            Response.Write("ok");
        }
     
        protected void linkSarch_Click(object sender, EventArgs e)
        {
            this.Literal1.Text = GetList();
        }
    }
}
